package com.china08.yxyapi.api.manage.sch.platform.website.setting;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.sws.SwsSetting;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.SwsSettingRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class SwsSettingSetsSchoolBadgeController extends YxyApiBaseController {

    @Autowired
    SwsSettingRepository swsSettingRepository;

    @ApiOperation("文章详情")
    @RequestMapping(value = "/api_yw/manage/sch/platform/website/setting/set/schoolbadge", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public void precess(HttpServletRequest request, HttpServletResponse response, @RequestBody ReqModel reqModel) {
        String schoolBadgeUrl = reqModel.schoolBadgeUrl;
        String schoolId = getProfile(request, response).getSchoolId();

        SwsSetting swsSetting = swsSettingRepository.findBySchoolId(schoolId);
        Assert.isTrue(null != swsSetting, "");

        swsSetting.setSchoolBadge(schoolBadgeUrl);
        swsSettingRepository.save(swsSetting);

    }

    protected static class ReqModel extends YxyApiReqModel {
        public String schoolBadgeUrl;

        @Override
        public void autoCheck() {
            Assert.isTrue(StringUtils.isNotBlank(schoolBadgeUrl), "学校校徽不能为空");
        }
    }

    protected static class RespModel extends YxyApiRespModel {
    }
}
